package org.looop.studio.bean.util;

import java.lang.reflect.InvocationTargetException;

public class BeanFactoryUtil {
	public static Object getInstance(String className) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
		return Class.forName(className).newInstance();
	}
	
	public static Object getInstance(String className, Object[] constructorArgs) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
		if(constructorArgs == null || constructorArgs.length == 0){
			return getInstance(className);
		}
		Class[] types = new Class[constructorArgs.length];
		for(int i=0; i < constructorArgs.length; i++){
			types[i] = constructorArgs[i].getClass();
		}
		return Class.forName(className).getConstructor(types).newInstance(constructorArgs);
	}
}
